﻿using MicroMq.Helper;
using MicroMq.Hosts;
using MicroMq.Options;
using MicroMq.Services;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;

using System.ComponentModel.Design;

namespace MicroMq
{
    internal class Program
    {
        static void Main(string[] args)
        {
            if (SystemctlHelper.RunCommand(args))
            {
                return;
            }
            Host.CreateDefaultBuilder(args)
                  .ConfigureServices(ConfigureServices).Build()
                  .Run();
        }

        public static void ConfigureServices(HostBuilderContext context, IServiceCollection services)
        {
            services.Configure<MicroMqOptions>(context.Configuration);
            services.AddLogging();
            services.AddSingleton<DelayWorkService>();
            services.AddSingleton<EventWorkService>();
            services.AddSingleton<DispatchWorkService>();

            
            services.TryAddSingleton<MqConnectionManager>();
            services.AddSingleton<IHandlerService, DispatchService>();
            services.AddSingleton<IHandlerService, SubscribeService>();
            services.AddSingleton<IHandlerService, DelayPublishService>();
            services.AddSingleton<IHandlerService, PublishSerivce>();
            services.AddHostedService<PeerHost>();

        }


    }
}
